package com.ynu.springbootappdemo.common.manager;


import com.aliyun.oss.OSSClient;
import com.aliyun.oss.model.PutObjectResult;
import com.ynu.springbootappdemo.common.system.OssClientConfig;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.io.File;

/**
 * Oss 对象存储操作
 *
 */
@Component
public class OssManager {

    @Resource
    private OssClientConfig ossClientConfig;

    @Resource
    private OSSClient ossClient;

    /**
     * 上传对象
     *
     * @param fileName 唯一键
     * @param file 文件
     * @return
     */
    public PutObjectResult putObject(String fileName, File file) {
        return ossClient.putObject(ossClientConfig.getBucket(), fileName, file);
    }
}
